package com.ptu.mapper;

import com.ptu.entity.Favorite;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface FavoriteMapper {

    @Insert("INSERT INTO favorite(user_id, product_id, create_time, update_time) " +
            "VALUES(#{userId}, #{productId}, NOW(), NOW())")
    void add(int userId, Integer productId);

    @Delete("DELETE FROM favorite WHERE user_id = #{userId} AND product_id = #{productId}")
    void delete(int userId, Integer productId);

    @Select("SELECT product_id FROM favorite WHERE user_id = #{userId}")
    List<Integer> getFavoriteList(int userId);
}
